
package com.jml.session;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@WebServlet("/GetSessionServlet")
public class GetSessionServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//参数默认为true，
		//为true表示如果没有sessionId就会创建session，否则不会创建session
		HttpSession session = req.getSession(true);
		String userName = (String) session.getAttribute("userName");
		System.out.println("userName:" + userName);
	}

}
